package com.fast.server.entity.responseVO;

import com.fast.server.entity.enums.RespBeanEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespBean {

    private long code;

    private String message;

    private Object obj;

    /**
     * 成功返回结果
     *
     * @return
     */
    public static RespBean success() {
        return new RespBean(RespBeanEnum.CODE_200.getCode(), RespBeanEnum.CODE_200.getMsg(), null);
    }

    public static RespBean success(Object obj) {
        return new RespBean(RespBeanEnum.CODE_200.getCode(), RespBeanEnum.CODE_200.getMsg(), obj);
    }

    /**
     * 失败返回结果,失败有很多种情况,所以直接传入RespBeanEnum
     */
    public static RespBean error(RespBeanEnum respBeanEnum, String SUPPLEMENTAL) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMsg() + ":" + SUPPLEMENTAL, null);
    }

    public static RespBean error(RespBeanEnum respBeanEnum) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMsg(), null);
    }

    public static RespBean error(RespBeanEnum respBeanEnum, Object obj) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMsg(), obj);
    }
}
